﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Petshop.Backend.Data;

namespace Petshop.Backend.DTO
{
    internal static class  Mapper
    {
        public static AccountInfo From(Account  account)
        {
            if (account == null) return null;
            var info = new AccountInfo();
            info.Address = new AddressInfo(account.FirstName, account.LastName, account.Addr1, account.Addr2, account.City, account.State, account.Zip , account.Country, account.Phone);
            info.Category = account.FavCategory;
            info.Email = account.Email;
            info.IsShowBanners = account.BannerOpt.HasValue && account.BannerOpt == 1 ? true : false;
            info.IsShowFavorites = account.MyListOpt.HasValue && account.MyListOpt == 1 ? true : false;
            info.Language = account.LangPref;
            info.Password = account.Password;
            info.UserId = account.UserId;
            return info;
        }

        internal static CategoryInfo From(Category category)
        {
            if (category == null) return null;
            var info = new CategoryInfo();
            info.BannerData = category.BannerData;
            info.CategoryID = category.CatId;
            info.Description = category.Descn;
            info.Name = category.Name;
            return info;
        }

        internal static ProductInfo From(Product product)
        {
            if (product == null) throw new ArgumentNullException("product");
            var info = new ProductInfo();
            info.Description = product.Descn;
            info.Id = product.ProductId;
            info.Name = product.Name;
            return info;
        }

        internal static ItemInfo From(Item item)
        {
            var info = new ItemInfo();
            info.Id = item.ItemId;
            info.Name = item.Description;
            info.Price = item.ListPrice.HasValue ? item.ListPrice.Value : 0;
            info.ProductDesc = item.Product.Descn;
            info.ProductName = item.Product.Name;
            info.Quantity = item.InventoryQty.HasValue?item.InventoryQty.Value:0;
            return info;
        }
    }
}
